﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

/// <summary>
/// Summary description for Util
/// </summary>
public class Util
{
    //public static string StringCleanup(string s)
    //{
    //    return s.Slugify();
    //}
    public static Guid StringToGuid(string s)
    {
        try
        {
            if (s == "-1")
            {
                return Guid.Empty;
            }
            else
            {
                return new Guid(s);
            }
        }
        catch
        {
            return Guid.Empty;
        }
    }
    public static Guid[] StringToGuid(string[] s)
    {
        Guid[] g = new Guid[s.Length];
        for (int i = 0; i < s.Length; i++)
        {
            g[i] = StringToGuid(s[i]);
        }
        return g;
    }
    public static string GetUniqueFilename(string filepath, string filename)
    {
        string uniqueName = filename;
        string filenameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filename);
        string extension = System.IO.Path.GetExtension(filename);
        bool c = true;
        int count = 1;
        while (c)
        {
            if (System.IO.File.Exists(filepath + uniqueName))
            {
                uniqueName = filenameWithoutExtension + "_" + count + extension;
                count++;
            }
            else
            {
                c = false;
            }
        }

        return uniqueName;
    }
}